import 'package:flutter/material.dart';
import '../../widgets/MyLocalImage.dart';
import 'package:fluttertoast/fluttertoast.dart';

import '../../main.dart';
import '../../res.dart';
import '../../widgets/TextView.dart';
import '../color/ColorUtils.dart';
import 'Tosat.dart';

class MyToast {
  void show(String tips,
      {ToastGravity? gravity, int? toastDuration, bool icon_tips = true}) {
    BuildContext context = navigatorKey.currentState!.overlay!.context;
    ToastSingleton.getInstance(context).showToast(
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16,vertical: 16),
        decoration: BoxDecoration(
            color: rgba(34, 34, 34, 1),
            borderRadius: BorderRadius.circular(6)),
        child: Wrap(
          direction: Axis.horizontal,
          spacing: 10,
          children: [
            MyLocalImage(
              icon_tips
                  ? Res.sys_icon_tips_success3x
                  : Res.sys_icon_tips_fail3x,
              width: 16,
              height: 16,
            ),
            Container(
              constraints: BoxConstraints(maxWidth: 300),
              child: TextView(
                tips,
                maxLines: 1,
                style: const TextStyle(color: Colors.white),
              ),
            ),
          ],
        ),
      ),
      gravity: gravity ?? ToastGravity.BOTTOM,
      fadeDuration: const Duration(milliseconds: 500),
      positionedToastBuilder: (context, child) {
        return Positioned(
          left: 0,
          right: 0,
          bottom: 100,
          child: child,
        );
      },
      toastDuration: Duration(seconds: toastDuration ?? 2),
    );
  }
}
